<?php

class CActionLinksPortlet extends CPortlet
{
	public function getRequiredParent()
	{
		return 'IPageCrud';
	}
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->setupLinks();
	}
	
	public function onPreRender($param)
	{		
		$this->displayLinks();
		parent::onPreRender($param);
	}
	
	protected function displayLinks()
	{
		$container=$this->getNamingContainer();
		$allowed=$container->allowedActions();
		
		$this->lnk_create->setVisible(in_array(CActionType::Create,$allowed) && ($container->getAction()===CActionType::View || $container->getAction()===CActionType::Read));
		//$this->lnk_delete->setVisible(in_array(CActionType::Delete,$allowed) && ($container->getAction()===CActionType::View || $container->getAction()===CActionType::Update));
	}

	protected function setupLinks()
	{
		$this->lnk_create->setText('Incluir');
		$this->lnk_create->setToolTip('Incluir novo registro.');
		$this->lnk_create->setCommandName(CActionType::Create);
		$this->lnk_create->onCommand=array($this->NamingContainer,'itemCommand');
		$this->lnk_create->setCssClass('add');
		$this->lnk_create->setVisible('false');

//		$this->lnk_delete->setText('Excluir');
//		$this->lnk_delete->setToolTip('Excluir o registro.');
//		$this->lnk_delete->setCssClass('del');
//		$this->lnk_delete->getAttributes()->onclick='return confirm(\'Tem certeza que deseja excluir este registro?\');';
//		$this->lnk_delete->setCommandName(CActionType::Delete);
//		$this->lnk_delete->OnCommand=array($this->NamingContainer,'itemCommand');
		$this->lnk_delete->setVisible('false');
	}
}